<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ko">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>콘텐츠관리 - 사이버선거역사관</title>
	<script src="../js/jquery.js" type="text/javascript"></script>
	<script src="../js/validator.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="../lib/editor/stylesheets/xq_ui.css" />
	<script type="text/javascript" src="../lib/editor/javascripts/XQuared.js?load_others=1"></script>
	<script type="text/javascript" src="../lib/editor/javascripts/plugin/FileUploadPlugin.js"></script>
	<script type="text/javascript">
	var xed; 
	
	window.onload = function() {
		xed = new xq.Editor("xqEditor");
	
		xed.isSingleFileUpload = true;
		xed.addPlugin('FileUpload');
		xed.setFileUploadTarget('/common/imageupload.do', null);
		xed.setEditMode('wysiwyg');
		xed.setWidth("100%");
	};
	</script>
	<script type="text/javascript">
        function reg(frm)
        {
			if(!checkAuth()) return false;
        	if (!isTextValidate(frm.article_title, "string", 0, "제목"))			return false;
    		if (!isTextValidate(frm.contents, "string", 0, "내용"))			return false;
    		
    		//내용
    		$('[name=article_content]').val(frm.contents.value);
    		
    		//상단공지여부
    		if ($('input[name="article_notice"]').is(":checked"))
			{
    			$('[name=article_notice_yn]').val('Y');
			}
			else
			{
				$('[name=article_notice_yn]').val('N');	
			}

    		return true;
        }
        //에디트
        function sendit()
        {
        	var frm = document.forms["frm"];
        	var contents = xed.getCurrentContent(true);
        	if (contents == "<p>&nbsp;</p>")
        	{
        		alert("내용을 입력하세요.");
        		return false;
        	}

        	return true;
        }
        
        $(function() {
			//첨부파일 추가		
			$('input[name=fileAdd]').click(function(){
				
				var count = 0;		
				var fileNum = 1;
				$('input:file[id="file"]').each(function(){
					count = count + 1;
					fileNum = fileNum + 1;
				});
				
				var bbs_file_count = $('[name=bbs_file_count]').val();
				var html = "<input type='file' id='file' name='file"+fileNum+"' /><br />";
			
				if(bbs_file_count <= count ){
					alert("첨부파일 갯수를 초과했습니다.");
					return false;
				}
				
				$('#fileTD').append(html);
				
			});
        });
       
    </script>
</head>
<body>
		<!-- 본문 영역 -->
		<div id="contents">
			<!-- 제목 및 Location 영역 -->
			<div id="location">
				<h3 id="contentTitle"></h3>
				<div id="locationPath"></div>
			</div>
			<script type="text/javascript">
			// 현재 메뉴 경로를 설정한다.
			var pagePath = licationPth.split("_");
			var pathStr = "홈";
			for( var i=0; i < pagePath.length; i++ )
			{
				if (i+1 >= pagePath.length)
					pathStr += " &gt; <strong>" + pagePath[i] + "</strong>";
				else
					pathStr += " &gt; " + pagePath[i]
			}
			document.getElementById("contentTitle").innerHTML = pagePath[ pagePath.length - 1 ];
			document.getElementById("locationPath").innerHTML = pathStr;
			</script>
			<!-- 본문 내용 -->
			<div id="content">
				<form name="writeFrm" method="post" action="../bbs/${ bbsMap.BBS_ID }_proc.do" onsubmit="return reg(this);" enctype="multipart/form-data">
				<input type="hidden" name="mode" value="follow" />
				<input type="hidden" name="bbs_id" id="bbs_id" value="${ bbsMap.BBS_ID }" />
				<input type="hidden" name="article_id" id="article_id" value="${ viewMap.ARTICLE_ID }" />
				<input type="hidden" name="article_ref" id="article_ref" value="${ viewMap.ARTICLE_REF }" />
				<input type="hidden" name="bbs_file_count" id="bbs_file_count" value="${ bbsMap.BBS_FILE_COUNT}"/>
				<input type="hidden" name="article_writer_id" id="article_writer_id" value="${ adminInfo.admin_id }" />
				<input type="hidden" name="article_content" id="article_content" value="" />
				<input type="hidden" name="article_reg_sort" id="article_reg_sort" value="a" />
    			<div class="ar">
					<span class="button btnProc01"><input type="submit" value="저장" /></span>
					<span class="button btnProc01"><a href="#" onclick="history.go(-1); return false;">취소</a></span>
				</div>
				<table cellspacing="0" cellpadding="0" border="0" class="tbl_type04">
					<colgroup>
						<col width="150px" />
						<col width="300px" />
						<col width="150px" />
						<col />
					</colgroup>
					<tbody>
						<tr>
							<th>제목</th>
							<td colspan="3"><input type="text" name="article_title" value="답변:] ${ viewMap.ARTICLE_TITLE }" size="105" maxlength="200" /></td>
						</tr>
						<c:if test="${ bbsMap.BBS_CATEGORY_YN eq 'Y' }" >
						<tr>
							<th>카테고리</th>
							<td colspan="3">
								<select name="article_category">
								<c:set var="category" value="${fn:split(bbsMap.BBS_CATEGORY,'|')}" />
								<c:forEach var="items" items="${category}" varStatus="g">
									<option value="${items}">${items}</option>
								</c:forEach> 
								</select>
							</td>
						</tr>
						</c:if>
						<tr>
							<th>공개여부</th>
							<td colspan="3">
								<input type="radio" name="article_open_yn" value="Y"  checked/> 공개
								<input type="radio" name="article_open_yn" value="N" /> 비공개
							</td>
						</tr>
						<tr>
							<th>등록자</th>
							<td colspan="3"><input type="text" name="article_writer" size="30" maxlength="50" value="${ adminInfo.admin_name }" /></td>
						</tr>
						<tr>
							<td colspan="4"><textarea id="xqEditor" name="contents"></textarea></td>
						</tr>
						<c:if test="${ bbsMap.BBS_FILE_COUNT ne '0'}">
						<tr>
							<th>첨부파일</th>
							<td colspan="3">
								<div id="fileTD">
								<input type="file" id="file" name="file1" /> <span class="button btnProc01"><input type="button" name="fileAdd" value="추가" /></span><br />
								</div>
							</td>
						</tr>
						</c:if>
					</tbody>
				</table>
				</form>
			</div>
		</div>
</body>
</html>
